package com.cuitrip.business.reminder.model;

import android.app.Activity;
import android.view.View;

import com.cuitrip.business.home.IndexActivity;
import com.cuitrip.business.order.OrderCreateActivity;
import com.cuitrip.push.model.PushMessageModel;
import com.cuitrip.service.R;
import com.cuitrip.util.ResourceUtil;
import com.cuitrip.util.time.InputTime;
import com.cuitrip.util.time.OutputTime;
import com.cuitrip.util.time.TimeUtil;

/**
 * Created by ak on 15/11/5.
 */
public class ConfirmFailViewHolder extends ReminderInfoViewHolder {







    @Override
    public void render(final PushMessageModel object) {
        serviceName.setText(object.getServiceName());
        title.setText(ResourceUtil.getString(R.string.book_popup_fail));
        if (object.getPersonCount() > 1){
            subTitle.setText(ResourceUtil.getString(R.string.book_popup_fail_desc_2, String.valueOf(object.getPersonCount())));
        }else{
            subTitle.setText(ResourceUtil.getString(R.string.book_popup_fail_desc_1));
        }
        String timeFormat = TimeUtil.formatTime(
                InputTime.build(object.getServiceDate(), TimeUtil.getZeroZone()),
                OutputTime.getInstance(OutputTime.OutputType.Type_DAY, TimeUtil.getZeroZone()));
        dateText.setText(timeFormat);
        actionStatus.setText(ResourceUtil.getString(R.string.attention_icon));
        actionStatus.setTextColor(ResourceUtil.getColor(R.color.mango_ffbb00));
        firstAction.setText(ResourceUtil.getString(R.string.book_operation_pick_another_date));
        secondAction.setText(ResourceUtil.getString(R.string.book_operation_book_other_trips));
        firstAction.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mWeakHostActivity.get().isNeedChangeType()) {
                    changeType("cuitrip://createorder?sid="+object.getSid());
                } else {
                    OrderCreateActivity.start(mWeakHostActivity.get(), object.getSid());
                }
            }
        });

        secondAction.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Activity activity = mWeakHostActivity.get();
                if (activity != null) {
                    dismiss();
                    if (mWeakHostActivity.get().isNeedChangeType()){
                        changeType("cuitrip://recommend");
                    }else{
                        IndexActivity.gotoTab(activity, IndexActivity.RECOMMEND_TAB_INDEX);
                    }
                }

            }
        });
    }


}
